home *** CD-ROM | disk | FTP | other *** search
- /*
- File: HTMLParser.h
-
- Contains: A simplistic parse of a sub-set of HTML.
- Used to allow styles in dialogs.
-
- Written by: Arno Gourdol
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #pragma once
-
- #ifndef __HTMLPARSER__
- #define __HTMLPARSER__
-
- #include <Script.h>
- #include <TextEdit.h>
- #include "CRect.h"
-
- class HTMLParser
- {
- public:
- // constructor
- HTMLParser(Handle text, SInt32 fromIndex = 0, SInt32 toIndex = -1);
-
- // destructor
- ~HTMLParser();
-
- void Parse(void);
-
- protected:
-
- // Tag hook functions
- virtual void TagBoldStart(SInt32 tagStart, SInt32 tagEnd);
- virtual void TagBoldEnd(SInt32 tagStart, SInt32 tagEnd);
- virtual void TagItalicStart(SInt32 tagStart, SInt32 tagEnd);
- virtual void TagItalicEnd(SInt32 tagStart, SInt32 tagEnd);
- virtual void EndOfText(SInt32 endOfText);
-
- // Tag utility functions
- Boolean IsTag(SInt32 tagStart, SInt32 tagEnd, ConstStr255Param tag);
- void Tag(SInt32 tagStart, SInt32 tagEnd);
-
- // Parse engine utility functions
- void SkipWhiteSpaces(void); // Move cursor until non white space
- inline void Abort(void); // Terminates parsing
- UInt16 GetChar(void); // Returns current character and advance
- SInt32 FindChar(UInt16 c); // Find a character, returns its index
- // do not change cursor
- inline SInt32 GetCursor(void); // Returns current index
- inline void SetCursor(SInt32 cursor); // Set current index
- inline SInt32 GetFinalCursor(void);
-
- char* fText;
-
- private:
-
- Handle fTextHandle;
- SignedByte fSavedHandleState;
- Boolean fContinue;
-
- SInt32 fCursor; // Current Index in the string
- SInt32 fFinalCursor;
- };
-
- void HTMLParser::Abort(void)
- {
- fContinue = false;
- }
-
-
- SInt32 HTMLParser::GetCursor(void)
- {
- return fCursor;
- }
-
-
- void HTMLParser::SetCursor(SInt32 cursor)
- {
- fCursor = cursor;
- if (fCursor > fFinalCursor)
- Abort();
- }
-
-
- SInt32 HTMLParser::GetFinalCursor(void)
- {
- return fFinalCursor;
- }
-
-
-
-
-
-
- class HTMLToStyledText : public HTMLParser
- {
- public:
- HTMLToStyledText(CRect frame, Handle text);
-
- TEHandle GetStyledText(void);
-
- protected:
- void ApplyTextStyles(SInt32 upToIndex);
-
- virtual void TagBoldStart(SInt32 tagStart, SInt32 tagEnd);
- virtual void TagBoldEnd(SInt32 tagStart, SInt32 tagEnd);
- virtual void TagItalicStart(SInt32 tagStart, SInt32 tagEnd);
- virtual void TagItalicEnd(SInt32 tagStart, SInt32 tagEnd);
- virtual void EndOfText(SInt32 endOfText);
-
- private:
- CRect fFrame;
- TEHandle fStyledText;
-
- // The fields below are counters representing the state
- // of the parsing
- SInt32 fLastTextStyleChange;
- UInt16 fBold;
- UInt16 fItalic;
- };
-
- void ConvertHTMLToStyledText(Handle text, CRect frame, TEHandle* textEdit);
-
- #endif
-